package com.ding;

import com.ding.dao.UserRepository;
import com.ding.pojo.User;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class JpaApplication {

    public static void main(String[] args) {
        ConfigurableApplicationContext context = SpringApplication.run(JpaApplication.class, args);
        UserRepository dao = context.getBean(UserRepository.class);

        System.out.println("dao的类"+dao.getClass()); //UserDao接口使用动态代理技术实现

        User user = new User("ding","666");
        user.addAuthority("user");
        user.addAuthority("admin");
        dao.save(user);                                 //使用继承来的sava方法

        user=dao.findByName("ding");                    //使用JPQL定义的功能
        user.setPassword("123");
        dao.saveAndFlush(user);

        user = dao.findUserByName("ding");              //使用混合自定义的功能
        System.out.println("用户ding的密码为"+user.getPassword());

        int count = dao.countByUsername("ding");        //使用由方法签名自定义的功能
        System.out.println("用户数量:"+count);

        dao.deleteById("ding");

        context.close();
    }
}
